/*
 * SPDX-License-Identifier: GPL-2.0
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved.
 * Description:
 * Author: -
 * Create:
 */

#include "ossl_knl.h"
#include "hiudk3.h"
#include "hiudk_internal.h"
/**
 * @brief hiudk_aeq_register_hw_cb -  register aeq hardware callback
 * @param udkdev: device pointer to udkdev
 * @param pri_handle: pointer to private dev
 * @param event: event type
 * @param hwe_cb: callback function
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_aeq_register_hw_cb(void *udkdev, void *pri_handle, enum hinic3_aeq_type event, hinic3_aeq_hwe_cb hwe_cb)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_aeq_register_hw_cb != NULL))) {
        return ops->hw_ops.hiudk_aeq_register_hw_cb(sdk_hwdev, pri_handle, event, hwe_cb);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_aeq_register_hw_cb);

/**
 * @brief hiudk_aeq_register_swe_cb -  register aeq soft event callback
 * @param udkdev: device pointer to udkdev
 * @param pri_handle: pointer to private dev
 * @param event: event type
 * @param aeq_swe_cb: callback function
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_aeq_register_swe_cb(void *udkdev, void *pri_handle, enum hinic3_aeq_sw_type event,
    hinic3_aeq_swe_cb aeq_swe_cb)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_aeq_register_swe_cb != NULL))) {
        return ops->hw_ops.hiudk_aeq_register_swe_cb(sdk_hwdev, pri_handle, event, aeq_swe_cb);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_aeq_register_swe_cb);

/**
 * @brief hiudk_aeq_unregister_hw_cb - unregister aeq hardware callback
 * @param udkdev: device pointer to udkdev
 * @param event: event type
 */
void hiudk_aeq_unregister_hw_cb(void *udkdev, enum hinic3_aeq_type event)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_aeq_unregister_hw_cb != NULL))) {
        return ops->hw_ops.hiudk_aeq_unregister_hw_cb(sdk_hwdev, event);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_aeq_unregister_hw_cb);

/**
 * @brief hiudk_aeq_unregister_swe_cb - unregister aeq soft event callback
 * @param udkdev: device pointer to udkdev
 * @param event: event type
 */
void hiudk_aeq_unregister_swe_cb(void *udkdev, enum hinic3_aeq_sw_type event)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_aeq_unregister_swe_cb != NULL))) {
        return ops->hw_ops.hiudk_aeq_unregister_swe_cb(sdk_hwdev, event);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_aeq_unregister_swe_cb);

/**
 * @brief hiudk_ceq_register_cb -  register ceq callback
 * @param udkdev: device pointer to udkdev
 * @param pri_handle: device pointer to private handle
 * @param event: event type
 * @param callback: callback function
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_ceq_register_cb(void *udkdev, void *pri_handle, enum hinic3_ceq_event event, hinic3_ceq_event_cb callback)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_ceq_register_cb != NULL))) {
        return ops->hw_ops.hiudk_ceq_register_cb(sdk_hwdev, pri_handle, event, callback);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_ceq_register_cb);

/**
 * @brief hiudk_ceq_unregister_cb - unregister ceq callback
 * @param udkdev: device pointer to udkdev
 * @param event: event type
 */
void hiudk_ceq_unregister_cb(void *udkdev, enum hinic3_ceq_event event)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_ceq_unregister_cb != NULL))) {
        return ops->hw_ops.hiudk_ceq_unregister_cb(sdk_hwdev, event);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_ceq_unregister_cb);

/**
 * @brief hiudk_register_service_adapter - register mgmt msg callback
 * @param udkdev: device pointer to udkdev
 * @param mod: mod type
 * @param pri_handle: private data will be used by the callback
 * @param callback: callback function
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_register_mgmt_msg_cb(void *udkdev, u8 mod, void *pri_handle, hinic3_mgmt_msg_cb callback)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_register_mgmt_msg_cb != NULL))) {
        return ops->hw_ops.hiudk_register_mgmt_msg_cb(sdk_hwdev, mod, pri_handle, callback);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_register_mgmt_msg_cb);

/**
 * @brief hiudk_register_pf_mbox_cb - pf register mbox msg callback
 * @param udkdev: device pointer to udkdev
 * @param mod: mod type
 * @param pri_handle: private data will be used by the callback
 * @param callback: callback function
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_register_pf_mbox_cb(void *udkdev, u8 mod, void *pri_handle, hinic3_pf_mbox_cb callback)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_register_pf_mbox_cb != NULL))) {
        return ops->hw_ops.hiudk_register_pf_mbox_cb(sdk_hwdev, mod, pri_handle, callback);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_register_pf_mbox_cb);

/**
 * @brief hiudk_register_ppf_mbox_cb - ppf register mbox msg callback
 * @param udkdev: device pointer to udkdev
 * @param mod: mod type
 * @param pri_handle: private data will be used by the callback
 * @param callback: callback function
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_register_ppf_mbox_cb(void *udkdev, u8 mod, void *pri_handle, hinic3_ppf_mbox_cb callback)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_register_ppf_mbox_cb != NULL))) {
        return ops->hw_ops.hiudk_register_ppf_mbox_cb(sdk_hwdev, mod, pri_handle, callback);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_register_ppf_mbox_cb);

/**
 * @brief hiudk_register_service_adapter - register service adapter
 * @param udkdev: device pointer to udkdev
 * @param service_adapter: service adapter
 * @param type: service type
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_register_service_adapter(void *udkdev, void *service_adapter, enum hinic3_service_type type)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_register_service_adapter != NULL))) {
        return ops->hw_ops.hiudk_register_service_adapter(sdk_hwdev, service_adapter, type);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_register_service_adapter);

/**
 * @brief hiudk_register_vf_mbox_cb - vf register mbox msg callback
 * @param udkdev: device pointer to udkdev
 * @param mod: mod type
 * @param pri_handle: private data will be used by the callback
 * @param callback: callback function
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_register_vf_mbox_cb(void *udkdev, u8 mod, void *pri_handle, hinic3_vf_mbox_cb callback)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return -EINVAL;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_register_vf_mbox_cb != NULL))) {
        return ops->hw_ops.hiudk_register_vf_mbox_cb(sdk_hwdev, mod, pri_handle, callback);
    }
    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_register_vf_mbox_cb);

/**
 * @brief hiudk_unregister_mgmt_msg_cb - unregister mgmt msg callback
 * @param udkdev: device pointer to udkdev
 * @param mod: mod type
 */
void hiudk_unregister_mgmt_msg_cb(void *udkdev, u8 mod)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_unregister_mgmt_msg_cb != NULL))) {
        return ops->hw_ops.hiudk_unregister_mgmt_msg_cb(sdk_hwdev, mod);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_unregister_mgmt_msg_cb);

/**
 * @brief hiudk_unregister_pf_mbox_cb - pf register mbox msg callback
 * @param udkdev: device pointer to udkdev
 * @param mod: mod type
 */
void hiudk_unregister_pf_mbox_cb(void *udkdev, u8 mod)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_unregister_pf_mbox_cb != NULL))) {
        return ops->hw_ops.hiudk_unregister_pf_mbox_cb(sdk_hwdev, mod);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_unregister_pf_mbox_cb);

/**
 * @brief hiudk_unregister_ppf_mbox_cb - ppf unregister mbox msg callback
 * @param udkdev: device pointer to udkdev
 * @param mod: mod type
 */
void hiudk_unregister_ppf_mbox_cb(void *udkdev, u8 mod)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_unregister_ppf_mbox_cb != NULL))) {
        return ops->hw_ops.hiudk_unregister_ppf_mbox_cb(sdk_hwdev, mod);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_unregister_ppf_mbox_cb);

/**
 * @brief hiudk_unregister_service_adapter - unregister service adapter
 * @param udkdev: device pointer to udkdev
 * @param type: service type
 */
void hiudk_unregister_service_adapter(void *udkdev, enum hinic3_service_type type)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_unregister_service_adapter != NULL))) {
        return ops->hw_ops.hiudk_unregister_service_adapter(sdk_hwdev, type);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_unregister_service_adapter);

/**
 * @brief hiudk_unregister_vf_mbox_cb - pf register mbox msg callback
 * @param udkdev: device pointer to udkdev
 * @param mod: mod type
 */
void hiudk_unregister_vf_mbox_cb(void *udkdev, u8 mod)
{
    void *sdk_hwdev = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return;
    }

    sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->hw_ops.hiudk_unregister_vf_mbox_cb != NULL))) {
        return ops->hw_ops.hiudk_unregister_vf_mbox_cb(sdk_hwdev, mod);
    }
    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_unregister_vf_mbox_cb);
